package com.baizhi.controller;

import com.baizhi.entity.CmfzAdmin;
import com.baizhi.service.CmfzAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class CmfzAdminController {
    @Autowired
    private CmfzAdminService cmfzAdminService;

    /*@RequestMapping("login")
    @ResponseBody
    public Map login(CmfzAdmin cmfzAdmin){
        Map map=new HashMap();
        CmfzAdmin user=cmfzAdminService.selectOne(cmfzAdmin);
        if(user==null){
            map.put("isLogin",false);
        }else {
            map.put("isLogin", true);
            map.put("user", user);
        }
        return map;
    }*/
    @RequestMapping("login")
    public String login(String username,String password, HttpSession session){
        CmfzAdmin user=cmfzAdminService.selectOne(username,password);
        if(user!=null){
            session.setAttribute("isLogin", true);
            session.setAttribute("user", user);
            return "main.main";

        }else {
            session.setAttribute("isLogin",false);
        }
        return "login";
    }

    @RequestMapping("loginOut")
    @ResponseBody
    public String loginOut(HttpSession session){
        session.removeAttribute("user");
        return "login";
    }
}
